package com.powernode.springmvc.controller;

import com.powernode.springmvc.bean.User;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author: 曾铖坚
 * @Date: 2024/10/7 23:39
 * @Version: 1.0.0
 */
//@Controller
@RestController
public class AJAXController {
    /*@GetMapping("/ajax")
    public String ajax(HttpServletResponse response) throws IOException {
        PrintWriter out = response.getWriter();
        out.print("hello ajax, my name is Spring MVC!");
        return null;
    }*/

    /*@GetMapping("/ajax")
    public void ajax(HttpServletResponse response) throws IOException {
        PrintWriter out = response.getWriter();
        out.print("hello ajax, my name is Spring MVC!");
    }*/

    /*@GetMapping("/ajax")
    @ResponseBody
    public String ajax() {
        //return "hello ajax, my name is Spring MVC!";
        return "{\"id\":\"123\",\"username\":\"zhangsan\",\"password\":\"1234\"}";
    }*/

    @GetMapping("/ajax")
    //@ResponseBody
    public User ajax() {
        User user = new User(123456L, "zhangsan", "123");
        return user;
    }
}
